require 'drb'

module REPLHost
  class Server
    def initialize
    end

    def evaluate(line, line_no)
      begin
        IRB.conf[:MAIN_CONTEXT].evaluate(line, line_no)
      rescue
        puts "REPL error: #{$!}" 
      end
    end
  end

  def self.init( port = 33668 )
    @@server = Server.new
    DRb.start_service("druby://127.0.0.1:#{port}", @@server)
  end
end


begin
  REPLHost.init

  at_exit do
    DRb.stop_service
  end
rescue
  puts "REPL server not started: #{$!}"
end

